package com.heima.selection.contoller;

import com.heima.selection.core.base.Ret;
import com.heima.selection.pojo.SysAuthToken;
import com.heima.selection.pojo.dto.UserLoginDto;
import com.heima.selection.service.UserService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

;

/**
 * @author YuanZiwen
 * @date 2025/6/22
 * @description LoginController
 */
@Slf4j
@SuppressWarnings("all")
@RestController
@RequestMapping("/sys/api/auth")
@RequiredArgsConstructor
public class AuthController {

    private final UserService userService;

    @PostMapping("/doLogin")
    public  Ret login(@RequestBody @Valid UserLoginDto dto) {
        log.info("登录收到参数 username:{}", dto.getUsername());
        SysAuthToken token = userService.doLogin(dto);
        return Ret.buildOk(token);
    }
}
